package com.cqc.jdk8.Jlang;

import org.junit.Test;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * @author cui
 * @date 2025/7/2 22:28
 * @description
 **/
public class MathTest {


    @Test
    public void f1() {
        int a = 7;
        int b = 2;
        double r1 = Math.ceil((double) a / b);
        System.out.println(r1);
        double r2 = Math.ceil(a * 1.0 / b);
        System.out.println(r2);
    }

    /**
     * 对list手动分页
     */
    @Test
    public void f3() {
        String[] arr = {"a", "b", "c", "d", "e", "f", "g", "h", "i"};
        List<String> list = Arrays.asList(arr);
        int total = list.size();
        int pageSize = 2;

        int totalPages = (int) Math.ceil(total * 1.0 / pageSize);
        for (int i = 0; i < totalPages; i++) {
            int fromIndex = i * pageSize;
            int toIndex = Math.min(fromIndex + pageSize, total);
            List<String> itemList = list.subList(fromIndex, toIndex);
            System.out.println("共" + totalPages + "页，这是第" + (i + 1) + "页。itemList：" + itemList);
        }
    }
}
